home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
olrdrs
/
qwktxt46.zip
/
QWKTXT46.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-25
|
14KB
|
467 lines
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <direct.h>
#include <dos.h>
#include <errno.h>
#include <process.h>
#include <stdlib.h>
#include <string.h>
#include "qwktxt46.h"
void _cdecl main(int argc, char **argv)
{
FILE *ifp, *ofp;
int i = 0, j;
int cn, Acc_confs;
char *sp;
char stuff[STUFF_SIZE];
char BBS_name[80];
char BBS_location[80];
char BBS_phone_number[25];
char Packet_date[12];
char Packet_time[9];
char User_name[25];
char temp[25];
char *unavailable = "Not provided.";
char fqpname[81]; /* fully qualified path name */
TotalMsgsInQWK = 0;
MsgsPerConference = 0;
printf("%c[2J",27);
printf("QWK2TXT %s QWK -> TXT converter\n", VERSION);
printf("Public Domain as of %s\n\n", REL_DATE);
if( (argc != 2) && (argc != 3) ) /* check for proper number of args */
{
printf("\n\tusage: qwktxt46 filename.qwk");
printf("\n\t -or- qwktxt46 filename.qwk P|U\n\n");
printf("\n\twhere: filename.qwk is your qwk file");
printf("\n\t P = use PKUNZIP.EXE");
printf("\n\t U = use UNZIP.EXE\n");
printf("\n\tNOTE: ONLY one of P or U may be used and if used, the");
printf("\n\t filename.qwk MUST be in .ZIP format. P or U is");
printf("\n\t not needed if the file is in another archive format.\n\n");
exit(1);
}
zipflag = toupper(argv[2][0]);
printf("Decompressing QWK file...One moment, please...\r");
if(mkdir("QWK$TMP") == -1)
{
printf("\n\tError: Can't create temporary subdirectory QWK$TMP.");
exit(1);
}
arctype = WhichArc(argv[1]);
switch(arctype)
{
case -1:
printf("\n\tFile %s not found.", argv[1]);
exit(1);
break;
case UNKNOWN:
printf("\n\tArchive method of %s is unknown.", argv[1]);
exit(1);
break;
case ARC:
chdir("QWK$TMP");
sprintf(fqpname, "arc x ..\\%s >nul", argv[1]);
break;
case ZOO:
chdir("QWK$TMP");
sprintf(fqpname, "zoo x ..\\%s >nul", argv[1]);
break;
case ARJ:
chdir("QWK$TMP");
sprintf(fqpname, "arj x ..\\%s >nul", argv[1]);
break;
case LHARC:
chdir("QWK$TMP");
sprintf(fqpname, "lharc x ..\\%s >nul", argv[1]);
break;
case LHA:
chdir("QWK$TMP");
sprintf(fqpname, "lha x ..\\%s >nul", argv[1]);
break;
case ZIP:
chdir("QWK$TMP");
if(zipflag == 'P')
sprintf(fqpname, "pkunzip ..\\%s >nul", argv[1]);
else if(zipflag == 'U')
sprintf(fqpname, "unzip ..\\%s >nul", argv[1]);
else
sprintf(fqpname, "pkunzip ..\\%s >nul", argv[1]);
break;
}
system(fqpname); /* decompress the file */
printf(" \n\n");
if ((ifp = fopen("control.dat", "r")) == NULL) /* open control.dat */
{
printf("\n\tRequired file CONTROL.DAT not found.");
exit(1);
}
if(fgets(stuff,STUFF_SIZE,ifp) != NULL) /* get BBS' name */
{
strip(stuff);
strcpy(BBS_name,stuff);
}
if(fgets(stuff,STUFF_SIZE,ifp) != NULL) /* get BBS' city/state */
{
strip(stuff);
if(stuff[0] == 0)
strcpy(BBS_location,unavailable);
else
strcpy(BBS_location,stuff);
}
if(fgets(stuff,STUFF_SIZE,ifp) != NULL) /* get BBS' phone number */
{
strip(stuff);
strcpy(BBS_phone_number,stuff);
}
fgets(stuff, STUFF_SIZE, ifp); /* toss sysop name into bit-bucket */
fgets(stuff, STUFF_SIZE, ifp); /* toss door reg. # and BBS ID too */
if(fgets(stuff,STUFF_SIZE,ifp) != NULL) /* get packet date & time */
{
strip(stuff);
strcpy(temp,stuff);
}
for(i=0; i<10; i++) /* strip packet date from string */
Packet_date[i] = temp[i];
Packet_date[10] = '\0';
for(i=11; i<19; i++) /* strip packet time from string */
Packet_time[i-11] = temp[i];
Packet_time[8] = '\0';
if(fgets(stuff,STUFF_SIZE,ifp) != NULL) /* get user's name */
{
strip(stuff);
strcpy(User_name,stuff);
}
for (i=0; i < 3; i++) /* Skip over Qmail menu filename, */
fgets(stuff, STUFF_SIZE, ifp); /* and two ASCII 0's */
fgets(stuff, STUFF_SIZE, ifp); /* get ASCII value of # of */
strip(stuff); /* conferences available */
Acc_confs = atoi(stuff); /* and convert it to int */
cn = i = 0;
for (;;) /* loop to identify all conferences */
{
if (!fgets(stuff, STUFF_SIZE, ifp))
break;
strip(stuff);
if (stuff[0] == 0)
break;
if (sscanf(stuff, "%d", &i) != 1) /* get conference number */
{ /* and convert to an int */
i = 1;
break;
}
if (!fgets(stuff, STUFF_SIZE, ifp)) /* get conference name */
{
printf("\n\tCorrupted conference name in CONTROL.DAT.");
exit(1);
}
strip(stuff);
confs[cn]._num = i;
confs[cn]._msgs = 0;
strcpy(confs[cn++]._name, byp(stuff));
}
if ((ofp = fopen("messages.txt", "w")) == NULL) /* open output file */
{
printf("\n\tUnable to open MESSAGES.TXT for output.");
exit(1);
}
sep(ofp); /* separate areas */
fprintf(ofp, " BBS Name: %s\n", BBS_name);
fprintf(ofp, " BBS Location: %s\n", BBS_location);
fprintf(ofp, "BBS Phone Number: %s\n", BBS_phone_number);
fprintf(ofp, " Packet Date: %s\n", Packet_date);
fprintf(ofp, " Packet Time: %s\n", Packet_time);
fprintf(ofp, " User Name: %s\n\n", User_name);
fprintf(ofp, "You have access to %d conference%s.\n", Acc_confs,
(Acc_confs == 1) ? "" : "s");
sep(ofp); /* separate info above from actual messages */
printf("Indexing conference: "); /* read *.NDX files and save that info */
for (i = 0; i < cn; i++)
confs[i]._msgs = nummsg(confs[i]._num);
putchar('\r');
for(i=0; i < 30; i++) /* get rid of "Indexing..." message */
putchar(' '); /* (only for aesthetics) */
fclose(ifp); /* finished with CONTROL.DAT so close it */
if ((ifp = fopen("messages.dat", "rb")) == NULL) /* open message packet */
{
printf("Unable to open required file MESSAGES.DAT.");
fclose(ofp);
exit(1);
}
if (readblk(ifp, stuff)) /* read in 1st record with Sparky's copyright */
{ /* abort if we can't read for some reason */
printf("\n\tCan't read Sparkware's copyright message in MESSAGES.DAT.");
fclose(ofp);
exit(1);
}
for (i = 0; i < cn; i++) /* main loop -- do for every conference */
{
printf("\rWorking on Conference %d [%s] ", i, confs[i]._name);
TotalMsgsInQWK += MsgsPerConference;
MsgsPerConference = 0; /* reset variable for next conference */
while (confs[i]._msgs--) /* as long as the conference has messages */
{
if (readhdr(ifp)) /* read the message header or abort if not found */
{
printf("\n\tCan't read message header in MESSAGES.DAT file.");
printf("\n\t\tConference: %d [%s]", i, confs[i]._name);
printf("\n\t\t Message #: %d", confs[i]._msgs);
fclose(ofp);
exit(1);
}
/* keep user's interest up by displaying useless info */
fpr